package Export;

/**
 * @description:
 * @author: cyy
 **/
public class methodXSSF {
    //控制层
    /*
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(HttpServletRequest request, HttpServletResponse response,String date){
        String realPath = request.getSession().getServletContext().getRealPath("/page");
        System.out.println("realpath+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"+realPath);
        TemplateInfo export = icqSafetyService.export(realPath, date);
        String userAgent = request.getHeader("USER-AGENT");
        String fileName = "安全考核成绩.xlsx";
        String finalFileName = null;
        ServletOutputStream outputStream = null;
        try {
            // IE浏览器
            if (org.apache.commons.lang.StringUtils.contains(userAgent, "MSIE")) {
                finalFileName = URLEncoder.encode(fileName, "UTF8");
            } else if (org.apache.commons.lang.StringUtils.contains(userAgent, "Mozilla")) {// google,火狐浏览器
                finalFileName = new String(fileName.getBytes(), "ISO8859-1");
            } else {
                finalFileName = URLEncoder.encode(fileName, "UTF8");// 其他浏览器
            }
            response.setHeader("Content-Disposition", "attachment; filename=\"" + finalFileName + "\"");// 这里设置一下让浏览器弹出下载提示框，而不是直接在浏览器中打开
            response.setContentType("application/vnd.ms-excel");
            outputStream = response.getOutputStream();
            export.getXssfWorkbook().write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (outputStream == null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (export.getFile() != null) {
                export.getFile().delete();
            }
        }
    }
    * */

    //业务层
    /*
    *public TemplateInfo export(String realPath,String date) {
        //查询数据
        List<Map<String, Object>> data = icqSafetyDao.getCheckScore(date);
        for(Map<String,Object> map : data){
            map.put("watermark","1".equals(map.get("watermark").toString())?"是":"否");
            map.put("safetyAudit","1".equals(map.get("safetyAudit").toString())?"是":"否");
            map.put("tamperProof","1".equals(map.get("tamperProof").toString())?"是":"否");
            map.put("encrypt","1".equals(map.get("encrypt").toString())?"是":"否");
            map.put("screen","1".equals(map.get("screen").toString())?"是":"否");
            map.put("fileProtect","1".equals(map.get("fileProtect").toString())?"是":"否");
            map.put("resAccurateRate",map.get("resAccurateRate").toString()+"%");
            map.put("weakPwdRate",map.get("weakPwdRate").toString()+"%");
            map.put("bugRate",map.get("bugRate").toString()+"%");
        }
        try {
            InputStream resourceAsStream = new FileInputStream(new File(realPath + "/excel/check_score.xlsx"));
            //设置导出文件数据
            TemplateInfo templateInfo = new TemplateInfo();
            templateInfo.setFirstWriteRow(5);
            templateInfo.setWriteRow(5);
            templateInfo.setDataName(new String[]{"civilName", "resNumber", "omoaNumber", "resAccurateRate", "resScore","resNumber","weakPwdRate",
                    "weakPwdScore","resNumber","bugRate", "bugScore", "illegalNumber", "illegalScore", "passNumber", "passScore", "watermark", "watermarkScore",
                    "safetyAudit", "safetyAuditScore", "tamperProof", "tamperProofScore", "safeNumber",
                    "encrypt", "encryptScore", "screen", "screenScore", "fileProtect", "fileProtectScore", "deduct", "totalScore"});
            templateInfo.setFile(new File(UUID.randomUUID().toString() + ".xlsx"));
            FileUtils.copyInputStreamToFile(resourceAsStream, templateInfo.getFile());
            templateInfo.setDatas(data);
            //开始写入
            return templateExportUtil.exportData(templateInfo);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    * */




}
